<?php

class Persion {
    private $salary;
    private $work_year = 0;
    private $payoff;
    public function __construct()
    {
        $this->payoff=new Payoff();
    }
    public function getSalary(){
        $this->salary=$this->payoff->pay($this);
        return $this->salary;
    }
    public function getWorkYear(){
        return $this->work_year;
    }
    public function setWorkYear($year = 0){
        $this->work_year = $year;
    }
}

class Payoff {
    public function pay(Persion $persion){
        $salary = 0;
        $year = $persion->getWorkYear();
        if($year <= 1){
            $salary = 1000;
        }else if($year>1 && $year<3){
            $salary = 2000;
        }else if($year >= 3){
            $salary = 3000;
        }
        return $salary;
    }
}
echo '<Hr>';

$lisi = new Persion();
echo '工龄是:'.$lisi->getWorkYear(),'年，工资是:'.$lisi->getSalary(),'元<br/>';
$lisi->setWorkYear(1);
echo '工龄是:'.$lisi->getWorkYear(),'年，工资是:'.$lisi->getSalary(),'元<br/>';
$lisi->setWorkYear(2);
echo '工龄是:'.$lisi->getWorkYear(),'年，工资是:'.$lisi->getSalary(),'元<br/>';
$lisi->setWorkYear(3);
echo '工龄是:'.$lisi->getWorkYear(),'年，工资是:'.$lisi->getSalary(),'元<br/>';

$zhangsan = new Persion();
$zhangsan->setWorkYear(5);
echo '工龄是:'.$zhangsan->getWorkYear(),'年，工资是:'.$zhangsan->getSalary(),'元<br/>';